layui.use(["laydate", "table", "element"], function () {
    var d = layui.jquery, a = layui.laydate, c = layui.table, b = layui.element;
    d.ajax({
        type: "GET",
        url: "/uc/schedule/ajax/user/yb",
        dataType: "json",
        data: {"content": 0, "title": ""},
        error: function () {
            console.log("请求失败！");
        },
        success: function (data) {
            var html = "";
            if ("" != data && null != data) {
                var dataList = data.dataList;
                if (null != dataList && dataList.length > 0) {
                    for (var i = 0; i < dataList.length; i++) {
                        html = html + "<div class='layui-row custom-tr' content='" + dataList[i].url + "'>" +
                            "<div class='custom-td td-first layui-col-md5 layui-col-sm5 layui-col-xs5'>" + dataList[i].title + "</div>" +
                            "<div class='custom-td layui-col-md2 layui-col-sm2 layui-col-xs2'>" + dataList[i].sqr + "</div>" +
                            "<div class='custom-td layui-col-md2 layui-col-sm2 layui-col-xs2'>" + dataList[i].name + "</div>" +
                            "<div class='custom-td layui-col-md3 layui-col-sm3 layui-col-xs3'>" + dataList[i].state + "</div>" +
                            "</div>";
                    }
                }
                d(".custom-yb-list").html(html);
                d(".custom-tr").off("click").on("click", function () {
                    var e = d(this).attr("content");
                    window.open(e)
                });
            }
        }
    });
    db();
    setInterval(db,10000);
    function db() {
        d.ajax({
            type: "GET",
            url: "/uc/schedule/ajax/user/db?date="+new Date(),
            dataType: "json",
            data: {"content": 0, "title": ""},
            error: function () {
                console.log("请求失败！");
            },
            success: function (data) {
                var html = "";
                if ("" != data && null != data) {
                    var dataList = data.dataList;
                    if (null != dataList && dataList.length > 0) {
                        for (var i = 0; i < dataList.length; i++) {
                            html = html + "<div class='layui-row custom-tr' content='" + dataList[i].url + "'>" +
                                "<div class='custom-td td-first layui-col-md5 layui-col-sm5 layui-col-xs5'>" + dataList[i].title + "</div>" +
                                "<div class='custom-td layui-col-md1 layui-col-sm1 layui-col-xs1'>" + dataList[i].sqr + "</div>" +
                                "<div class='custom-td layui-col-md2 layui-col-sm2 layui-col-xs2'>" + dataList[i].workname + "</div>" +
                                "<div class='custom-td layui-col-md2 layui-col-sm2 layui-col-xs2'>" + dataList[i].description + "</div>" +
                                "<div class='custom-td layui-col-md2 layui-col-sm2 layui-col-xs2'>" + dataList[i].dqsj + "</div>" +
                                "</div>";
                        }
                    }
                    d(".custom-db-list").html(html);
                    d(".custom-tr").off("click").on("click", function () {
                        var e = d(this).attr("content");
                        window.open(e)
                    });
                }
                if(""==html){
                    d(".layui-p-db").addClass("layui-p-db-hid").children("span").html("");
                }else {
                    d(".layui-p-db").removeClass("layui-p-db-hid").children("span").html(dataList.length);
                }
            }
        });
    }
    d.ajax({
        type: "GET",
        url: "/uc/schedule/ajax/user/dispatch",
        dataType: "json",
        data: {"content": 0, "title": ""},
        error: function () {
            console.log("请求失败！");
        },
        success: function (data) {
            var html = "";
            if (null != data && "" != data) {
                var dataList = data.dataList;
                if (null != dataList && dataList.length > 0) {
                    for (var i = 0; i < dataList.length; i++) {
                        html = html + "<div class='layui-row custom-tr-1 custom-dispatch' content='" + dataList[i].id + "'>" +
                            "<div class='custom-td td-first layui-col-md8 layui-col-sm8 layui-col-xs8'>" + dataList[i].bt + "</div>" +
                            "<div class='custom-td layui-col-md4 layui-col-sm4 layui-col-xs4'>" + dataList[i].wh + "</div>" +
                            "</div>";
                    }
                }
                d(".custom-dispatch-list").html(html);
                d(".custom-dispatch").on("click", function () {
                    var e = d(this).attr("content");
                    layer.open({
                        type: 2,
                        area: ["10px", "10px"],
                        fixed: false,
                        maxmin: false,
                        content: "/uc/schedule/entity/" + e + "/dispatch"
                    })
                });
            }
        }
    });

    a.render({
        elem: "#customDate", position: "static", change: function (f, e) {
        }
    });

    d(".custom-db-more").on("click", function () {
        window.open("/uc/schedule/list/db")
    });
    d(".custom-yb-more").on("click", function () {
        window.open("/uc/schedule/list/yb")
    });
    b.on("tab(card)", function (f) {
        var e = d(this).attr("lay-id");
        d(".custom-more").attr("content", e)
    });
    d(".custom-more").on("click", function () {
        var e = d(this).attr("content");
        if ("" != e && undefined != e) {
            window.open(e)
        }
    });
    d(".custom-lecture").on("click", function () {
        var e = d(this).attr("content");
        layer.open({
            type: 2,
            area: ["80%", "80%"],
            fixed: false,
            maxmin: true,
            title: "学校讲座",
            content: "/uc/schedule/entity/" + e + "/lecture"
        })
    });


    d.ajax({
        type: "GET", url: "/uc/schedule/list/notice",data: {"content": 0, "title": ""},dataType: "json", error: function (e) {
            console.log("Connection error");
        }, success: function (h) {
            var g = "";
            if(null!=h&&""!=h){
                var f = h.dataList;
                if (null != f && f.length > 0) {
                    for (var e = 0; e < f.length; e++) {
                        g = g + "<div class='layui-row custom-tr-1 custom-notice' content='" + f[e].id + "'>" +
                            "<div class='custom-td td-first layui-col-md6 layui-col-sm6 layui-col-xs6' >" + f[e].title + "</div>" +
                            "<div class='custom-td layui-col-md3 layui-col-sm3 layui-col-xs3'>" + f[e].foldername + "</div>" +
                            "<div class='custom-td layui-col-md3 layui-col-sm3 layui-col-xs3'>" + f[e].publishtime + "</div></div>";
                    }
                }
                d(".notice").html(g);
                d(".custom-notice").on("click", function () {
                    var e = d(this).attr("content");
                    window.open("/uc/schedule/notice/" + e + "/index");
                });
            }
        }
    });
    d.ajax({
        type: "GET", url: "/uc/schedule/application/ajax",data: {"content": 0, "title": ""}, dataType: "json", error: function (e) {
            console.log("Connection error")
        }, success: function (h) {
            if (null != h&&""!=h) {
                var g = "";
                var f = h.dataList;
                if (null != f && f.length > 0) {
                    for (var e = 0; e < f.length; e++) {
                        g = g + "<a class='layui-col-xs2 layui-col-sm2 layui-col-md2 custom-col' " + "href='" + f[e].path + "' target='_blank'>" + "<img src='" + f[e].image + "'/>" + "<span>" + f[e].name + "</span></a>"
                    }
                }
                d(".layui-tab-content .layui-show").html(g)
            }
        }
    });
    d.ajax({
        type: "GET", url: "/uc/schedule/application/ajax/summary",data: {"content": 0, "title": ""}, dataType: "json", error: function (e) {
            console.log("Connection error")
        }, success: function (g) {
            if (null != g&&""!=g) {
                var f = "";
                var h = g.yhsf;
                var e = g.data;
                if (null != e) {
                    if (h == "2") {
                        f = "<p>您一卡通余额为：<span style='color: red'>" + e.yktye + "</span>&nbsp;&nbsp;" + ";未还图书：<a style='color: red;cursor: pointer;' target='_blank' href='/uc/schedule/list/books'>" + e.whtsl + "</a>&nbsp;&nbsp;" + ";图书欠费：<span style='color: red;'>" + e.tsqf + "</span>&nbsp;&nbsp;" + "</p>"
                    } else {
                        f = "<p>您一卡通余额为：<span style='color: red'>" + e.yktye + "</span>&nbsp;&nbsp;" + ";未还图书：<a style='color: red;cursor: pointer;' target='_blank' href='/uc/schedule/list/books'>" + e.whtsl + "</a>&nbsp;&nbsp;" + ";" +
                            "图书欠费：<span style='color: red'>" + e.tsqf + "</span>&nbsp;&nbsp;" + ";" +
                            "财务欠费：<span style='color: red'>" + e.xsqf + "</span>&nbsp;&nbsp;" + ";" +
                            "费用明细：<a style='color: red;cursor: pointer;' target='_blank' href='/uc/schedule/list/mis'>查看</a>&nbsp;&nbsp;" + ";" +
                            "行为学分：<span style='color: red'>" + e.xwxf + "</span>&nbsp;&nbsp;" + ";" +
                            "学位绩点：<span style='color: red'>" + e.xwjd + "</span>&nbsp;&nbsp;" + ";" +
                            "英语绩点：<span style='color: red'>" + e.yyjd + "</span>&nbsp;&nbsp;" + ";" +
                            "英语四级：<span style='color: red'>" + e.cet4 + "</span>&nbsp;&nbsp;" + ";" +
                            "上课缺勤：<span style='color: red'>" + e.knjc + "</span>次&nbsp;&nbsp;" + ";" +
                            "晚自习缺勤：<span style='color: red'>" + e.wzx + "</span>次&nbsp;&nbsp;" + ";" +
                            "早上迟到：<span style='color: red'>" + e.zscd + "</span>次&nbsp;&nbsp;" + "</p>"
                    }
                    console.log(f);
                }
                d(".layui-tx").append(f);
            }
        }
    })
});